




set seed 26102015
use Data/sample_income_discountoc_angle.dta, clear

merge 1:1 account_number read_date hour using Data/Andrea/sample_map_netghi.dta

keep if hhhour_sample ==1

	gen price = peakoffpeak_price + pexport_oc


 
	
	forval x = 1(1)24 {
		
		gen hour_price`x' = hours`x' * price // price variables 
		}
 
 
 gen household_hour = string(account_number) + string(hour)
destring household_hour, replace
 
 quietly tsls consumption hour_hdd* hour_cdd* cross* (hour_price*  virtualincome  =  hour_sun_PFIT*  PV_production  hour_base*), fe(household_hour) cluster(account_number) demean

 
 predict conshat 
 
 gen diff = consumption_kWh - conshat
 by account_number hour, sort: egen fixedeffect= mean(diff)
 
 
 
 
 rename virtualincome_dis actual_virtualincome
 
keep if hour ==12
	
gen price_rd = round(price)

label variable price_rd "Price (c/kWh)"

graph drop _all

	
* suppose solar production = 4kWh
gen simPV_high= 4
gen virtualincome_dis = price* simPV

predict simconshat_high
replace simconshat_high = simconshat_high + fixedeffect 
replace simconshat_high =0 if simconshat_high<0
gen simexporthat_high = simPV - simconshat_high
replace simexporthat_high = 0 if simexporthat_high<0


by price_rd, sort: egen meansimexporthat_high = mean(simexporthat_high)

label variable meansimexporthat_high "Predicted supply (kWh)"

twoway (scatter price_rd meansimexporthat_high, msymbol(plus) mcolor(gs0) msize(vlarge)) ///
 (lfit price_rd meansimexporthat_high , lpattern(solid) lcolor(gs8)), name(simhigh) ///
legend(off) title(Panel B. Supply (high production), position(11) size(large) ring(7)) yscale(range(0 65)) scheme(s2mono) graphregion(color(white))

drop virtualincome_dis

* suppose solar production = 0.5kWh

gen simPV_low=0.5
gen virtualincome_dis = price* simPV_low

predict simconshat_low
replace simconshat_low = simconshat_low + fixedeffect 
replace simconshat_low = 0 if simconshat_low <0
gen simexporthat_low = simPV_low - simconshat_low
replace simexporthat_low = 0 if simexporthat_low<0

by price_rd, sort: egen meansimexporthat_low = mean(simexporthat_low)

label variable meansimexporthat_low "Predicted supply (kWh)"

twoway (scatter price_rd meansimexporthat_low, msymbol(plus) mcolor(gs0) msize(vlarge) ) ///
(lfit price_rd meansimexporthat_low , lpattern(solid) lcolor(gs8)) , name(simlow) ///
legend(off) title(Panel A. Supply (low production), position(11) size(large) ring(7)) yscale(range(0 65)) scheme(s2mono) graphregion(color(white))


drop virtualincome_dis





graph combine simlow simhigh 

graph export Results/Andrea/basesupplycurves.pdf, replace







